import 'package:flutter/material.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBNavigator.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBMineModule/YBQiYePersonPage/YBNumberManagerProvider/YBNumberManagerEventBus.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBNetWorkModule/YBBaseMineNetWork/YBBaseMineNetWork.dart';

class YBNumberInPutEditingPage extends StatefulWidget {

  final String titleHeader;
  final String contentTitle;
  final String memberCode;
  const YBNumberInPutEditingPage({Key key, this.titleHeader, this.contentTitle,this.memberCode}) : super(key: key);

  @override
  _YBNumberInPutEditingPageState createState() => _YBNumberInPutEditingPageState(titleHeader:titleHeader,contentTitle: contentTitle,memberCode: memberCode);
}

class _YBNumberInPutEditingPageState extends State<YBNumberInPutEditingPage> {

  final String titleHeader;
  final String contentTitle;
  final String memberCode;
  _YBNumberInPutEditingPageState({this.titleHeader, this.contentTitle,this.memberCode});

  TextEditingController _editingController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _editingController.text = contentTitle;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
         appBar: AppBar(
           title: Text(titleHeader,style: YBTextStyle.TextStyle30313320Medium),
           elevation: 0,
           actions: [
             Container(
               child: InkWell(
                 child: Container(
                   alignment: Alignment.center,
                   child: Padding(
                     padding:EdgeInsets.only(right: YBTextStyle.adapterSize10),
                     child: Text(
                       YBChineseText.mineCompleteTitle,
                       style: YBTextStyle.TextStyle30313312,
                     ),
                   ),
                 ),
                 onTap: () async {
                  _editingNumber(_editingController.text);

                 },
               ),
             ),
           ],
         ),
         body: SingleChildScrollView(
           child: Column(
             children: [
               Container(
                 height: YBTextStyle.adapterSize10,
               ),
               Container(
                 height: YBTextStyle.adapterSize45,
                 color: YBColor.white,
                 child: Padding(
                   padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                   child: TextField(
                     decoration: InputDecoration(
                       hintText: '${YBChineseText.mineQingInputTitle}$titleHeader',
                       border: InputBorder.none,
                     ),
                     controller: _editingController,
                   ),
                 ),
               ),
             ],
           ),
         ),
       ),
    );
  }

  void _editingNumber(String editingTextStr){

    Map<String, dynamic> editingTextMap = Map<String,dynamic>();
    editingTextMap['sysCode'] = "xg_youbang";
    editingTextMap['memberCode'] = memberCode;
    if (titleHeader.contains("姓名") == true){
      editingTextMap['memberName'] = editingTextStr;
    }

    if (titleHeader.contains("电话") == true){
      editingTextMap['memberPhone'] = editingTextStr;
    }


    if (titleHeader.contains("微信号") == true){
      editingTextMap['memberWxNumber'] = editingTextStr;
    }

    if (titleHeader.contains("邮箱") == true){
      editingTextMap['memberEmail'] = editingTextStr;
    }

    if (titleHeader.contains("部门") == true){
      editingTextMap['memberDepartment'] = editingTextStr;
    }

    if (titleHeader.contains("职位") == true){
      editingTextMap['memberJobTitle'] = editingTextStr;
    }

    YBMineNetWork.mineEditingZuZhiNumberManagerData(editingTextMap,success: (data){
      print('---$data');
      bool dataBool = data['body'];
      if (dataBool == true) {
        numberManagerEventBus.fire(YBNumberManagerEventBus(
            title: titleHeader, content: editingTextStr));
        YBNavigatorUtil.goDefaultBack(context);
      }
    },fail: (error){
      print('object-----$error');
    });
  }

}
